home *** CD-ROM | disk | FTP | other *** search
- Path: mother.usf.edu!news
- From: yatesc@csee.usf.edu (Randy Yates)
- Newsgroups: comp.lang.c++
- Subject: Re: what getline returns? Nobody can explain this!!
- Date: 19 Mar 1996 15:20:51 GMT
- Organization: University of South Florida
- Distribution: na
- Message-ID: <4imjcj$cf3@mother.usf.edu>
- References: <4ifbk8$6nf@bcarh8ab.bnr.ca>
- NNTP-Posting-Host: ppp129.cfr.usf.edu
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.93.14
-
- In article <4ifbk8$6nf@bcarh8ab.bnr.ca>, liyu@bnr.ca says...
- >
- >getline member fuction in ifstream is supposed to return the
- >receiving object (that is, ostream&).
- >
- >However, many books contain the code samples like:
- >
- >ifstream in("tmp.txt");
- >while (in.getline(buffer,sizeof(buffer))) { ... }
- >
- >This loop quits only if in.getline returns 0 or NUll;
- > ^^^^^^^
- >
- >but an ostream object is neither 0 nor NULL;
- >the result is an object, not integer or pointer.
- >
- >So how can this loop quit?
- >
- >It works; but no one I know can explain this!!!!
- >Thanks for your help.
-
- First of all, the getline member function returns an
- istream, not ostream.
-
- Are you sure the code is not this:
-
- while (!in.getline(buffer,sizeof(buffer))) { ... }
-
- I did a little research since my last post. What's happening
- is that the ios class (from which istream is derived) overloads
- the "!" operator to return the "fail" flag, which indicates
- whether or not the last I/O operation failed.
- --
- % Randy Yates % "...the answer lies within your soul
- % EE/Mathematics Student % 'cause no one knows which side
- % University of South Florida % the coin will fall."
- % <yatesc@csee.usf.edu> % 'Big Wheels', *Out of the Blue*, ELO
-
-